use rand;

use usrtrust::{UTime,SysTime,SysConvertor,Clocker,CpuClock,UClock,UClockExchange,TwoStage};
use usrtrust::{ULogs,Environment,SysBlocks};
use std::path::{Path};
use std::io::{Write,Result};
use std::thread;
use std::time::Duration;

fn main() -> Result<()> {
    let e = Environment::from_dir(Path::new("/tmp/usrtos"))?;
    let fsys = e.find("system_block")?;
    println!("{}",fsys);
    let mut sys = SysBlocks::new(fsys)?;
    let mut clkex = sys.get_items::<UClockExchange>("clock_a")?;
    let mut uclock = UClock::<CpuClock>::from_data(&mut clkex);
    let mut ts = TwoStage::<CpuClock>::default();
    loop {
        println!("{:?}",ts.state());
        println!("clock {:?}",uclock);
        match ts.one_ls() {
            Some(uc) => {
                uclock=uc;
                // uclock.to_data(&mut clkex);
            },
            None => {},
        }
    }
    Ok(())
}